<%@ page language="java" contentType="text/html; charset=UTF-8" 
import="com.google.appengine.api.datastore.KeyFactory,java.util.*,org.windblog.core.entity.*,org.windblog.core.*"  pageEncoding="UTF-8"%>
<%
	String Pdeleted = request.getParameter("deleted");
	int deleted = 0;
	if(Pdeleted!=null)
	{
		deleted = Integer.parseInt(Pdeleted);
	}
	
	String category_name = request.getParameter("category_name");
	List<Post> posts = null ;  //要列出的post

	if(category_name !=null)
	{
		Category cat = CategoryService.getCategory(category_name);
		posts = cat.getPosts();
	}
	else{
		posts = PostService.getPosts("");
	}
%>
		<jsp:include page="header.jsp"></jsp:include>
		<jsp:include page="sidebar.jsp"></jsp:include>
		<script type="text/javascript">
			$(function(){
				// Accordion
				$("#accordion").accordion("activate",0);
				$("#post_edit").prepend(">");
			});
		</script>
		<div id="content">
			<h2>EditPost</h2>
			<hr/>
			<% if(deleted!=0){%>
			<div class="ui-widget" style="width:50em">
			<div class="ui-state-highlight ui-corner-all" style="margin-top: 20px; padding: 0 .7em;"> 
				<p><span class="ui-icon ui-icon-info" style="float: left; margin-right: .3em;"></span>
				<%
				if(deleted==1)
				{
					out.print("Post deleted.");
				}else {
					out.print(deleted+" posts deleted.");
				}
				%></p>
			</div>
			</div><br/>
			<%} 
			%>
			<div id="postspanel" class="ui-widget ui-widget-content ui-corner-all" style="margin-top:10px;padding:0;width:800px"> 
			<h3 class="ui-widget-header" style="padding:5px 10px;font-size:12px;">Posts</h3>
				<table id="posts" border="1" cellspacing="0" style="width:100%">
					<thead>
					<tr>
						<th>Post</th>
						<th>Author</th>
						<th>Categories</th>
						<th>Comments</th>
						<th>Date</th>
					</tr>
					</thead>
					<%
						
						if(posts!=null)
						{
							for(Post post:posts)
							{
								%>
					<tr  class="mzone">
						<td><strong><a href="<%=post.getEditLink() %>"><%= post.getTitle() %> </a></strong><div>&nbsp;<span class="Action" style="display:none"><a href="<%=post.getEditLink() %>">Edit</a>|<a href="<%=post.getDeleteLink() %>">Delete</a>|<a href="<%=post.getPermalink() %>">View</a></span></div></td>
						<td><%=post.getAuthor() %></td>
						<td><%
						List<Category> cats = post.getCategories();
						if(cats.size()==0)
						{
							%>
							未分类.
							<%
						}
						for(Category cat : cats)
						{
							%>
							<a href="/admin/editPost.jsp?category_name=<%=cat.getName()%>" ><%=cat.getName() %></a>.
						<%
						}
						%></td>
						<td><%=post.getComments().size() %></td>
						<td><%=post.getFormatedDate() %></td>
					</tr>
					
								<%
							}
						}
					%>
				</table>
			</div> 
		</div>
		<jsp:include page="footer.jsp"></jsp:include>
